package com.anjubao.parking.municipal.parkinglot.service;

import cn.hutool.core.date.DateUtil;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingStatTradesResDto;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingTrentTradesResDto;
import com.anjubao.parking.municipal.parkinglot.mapper.ParkingStatTradesMapper;
import com.anjubao.parking.municipal.parkinglot.model.ParkingStatTrade;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * ParkingStatTrades服务实现类
 * @author anjubao
 */
@Service
@Slf4j
public class ParkingStatTradesService extends ServiceImpl<ParkingStatTradesMapper, ParkingStatTrade> {

    @Autowired
    private ParkingStatTradesMapper parkingStatTradesMapper;

    /**
     * 根据城市id和停车场类型统计当日各类型停车场费用总数
     * @param cityId
     * @param type
     * @return
     */
    public List<ParkingStatTradesResDto> findStatTrades(Integer cityId, Integer type){
        return parkingStatTradesMapper.findStatTrades(cityId, type);
    }

    public List<ParkingTrentTradesResDto> getParkingTrendTeades(Integer cityId, Integer type) {
        String hour= DateUtil.format(new Date(), "HH");
        if(hour.equals(0)){
            return parkingStatTradesMapper.getParkingTrendTeades(cityId,type,0);
        }
        return parkingStatTradesMapper.getParkingTrendTeades(cityId,type,Integer.valueOf(hour)-1);
    }
}
